package com.tczs.web.action;

import com.alibaba.fastjson.JSONObject;
import com.tczs.web.config.NeedLogin;
import com.tczs.web.service.DataService;
import com.tczs.web.service.TableService;
import org.apache.log4j.Logger;

public class DataAction {

    private static Logger logger = Logger.getLogger(DatabaseAction.class);

    /**
     *
     * @param method
     * @param databaseName
     * @param tableName
     * @param page 第几页
     * @return
     */
    @NeedLogin
    public JSONObject findData(String method,String databaseName,String tableName,String page){
        logger.info("entry findData.........");
        DataService dataService = new DataService();
        JSONObject data = dataService.findData(databaseName, tableName, Long.parseLong(page));
        JSONObject jsonObject = dataService.selectCount(databaseName, tableName);
        Long count = jsonObject.getJSONObject("data").getLong("count");
        JSONObject result = new JSONObject();
        result.put("code",200);
        result.put("count",count);
        result.put("pages",count/DataService.PAGE_SIZE==0?count/DataService.PAGE_SIZE:count/DataService.PAGE_SIZE+1);
        result.put("data",data.get("data"));
        logger.info(result.toJSONString());
        return result;
    }
}
